package com.dy.convert;

import com.dy.dto.WagesAddDTO;
import com.dy.dto.WagesExcelDTO;
import com.dy.dto.WagesUpdateDTO;
import com.dy.entity.WagesEntity;
import com.dy.vo.WagesVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * @Author: dy
 * @date: 2024/5/8 14:59
 * @ClassDescription:
 */
@Mapper(componentModel = "spring")
public interface WagesConvert {

    /**
     * 分页转换
     * @param entity entity
     * @return {@link WagesVO}
     */
    WagesVO wagesToVo(WagesEntity entity);

    /**
     * 添加
     * @param dto dto
     * @return {@link WagesEntity}
     */
    WagesEntity wagesAddDtoToWagesEntity(WagesAddDTO dto);

    /**
     * 修改
     * @param dto dto
     * @return {@link WagesEntity}
     */
    WagesEntity wagesUpdateDtoToWagesEntity(WagesUpdateDTO dto);

    /**
     * 导入
     * @param wagesExcelDtoList wagesExcelDtoList
     * @return {@link List}<{@link WagesEntity}>
     */
    List<WagesEntity> wagesExcelDtoListToWagesEntityList(List<WagesExcelDTO> wagesExcelDtoList);

    /**
     * 导入
     * @param wagesExcelDto wagesExcelDto
     * @return {@link WagesEntity}
     */
    @Mappings(
            @Mapping(target = "recordDate",expression = "java(wagesExcelDto.getRecordDate()==null?null:java.time.LocalDate.parse(wagesExcelDto.getRecordDate(),java.time.format.DateTimeFormatter.ofPattern(\"yyyy-MM-dd\")))")
    )
    WagesEntity wagesExcelDtoToWagesEntity(WagesExcelDTO wagesExcelDto);

    /**
     * 导出
     * @param entityList entityList
     * @return {@link List}<{@link WagesExcelDTO}>
     */
    List<WagesExcelDTO> wagesEntityListToWagesExcelDtoList(List<WagesEntity> entityList);

    /**
     * 导出
     * @param wagesEntity wagesEntity
     * @return {@link WagesExcelDTO}
     */
    @Mappings(
            @Mapping(target = "recordDate",expression = "java(wagesEntity.getRecordDate() == null ? null : wagesEntity.getRecordDate().format(java.time.format.DateTimeFormatter.ofPattern(\"yyyy-MM-dd\")))")
    )
    WagesExcelDTO wagesToWagesExcelDto(WagesEntity wagesEntity);

}
